int shortestPathBinaryMatrix(int** grid, int gridSize, int* gridColSize){
    if(grid[0][0] == 1 || grid[gridSize - 1][gridColSize[0] - 1] == 1)
        return -1;
    int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
    int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};

    int count = 0;
    int q[gridSize * gridColSize[0]][2], r = 0, l = 0;

    grid[0][0] = 1;
    q[r][0] = 0; q[r++][1] = 0;
    while(l < r){
        count++;
        int size = r - l;
        for(int i = 0; i < size; i++){
            int x = q[l][0], y = q[l++][1];
            if( x == gridSize - 1 && y == gridColSize[0] - 1)
                return count;
            for(int k = 0; k < 8; k++){
                int mx = x + dx[k], my = y + dy[k];
                if(mx >= 0 && mx < gridSize && my >= 0 && my < gridColSize[0] && grid[mx][my] == 0){
                    grid[mx][my] = 1;
                    q[r][0] = mx; q[r++][1] = my;
                }
            }
        }
    }
    return -1;
}